﻿using System.Collections.Generic;
using ValidationEngine.Commons.Interfaces;

namespace ValidationEngine.Commons
{
    /// <summary>
    /// Validator interface
    /// </summary>
    public interface IValidator
    {
        /// <summary>
        /// Runs validator rules for property from ctx.
        /// </summary>
        /// <param name="ctx">Validation context</param>
        /// <returns>Validation info.</returns>
        IValidationInfo Validate(IValidationContext ctx);

        /// <summary>
        /// Runs all validator rules for model from context.
        /// </summary>
        /// <param name="ctx">Validation context</param>
        /// <returns>Validation info.</returns>
        Dictionary<string, IValidationInfo> ValidateAll(IValidationContext ctx);

        /// <summary>
        /// Runs all validator rules for model parameter.
        /// </summary>
        /// <param name="model">Model instance</param>
        /// <returns>Validation info</returns>
        Dictionary<string, IValidationInfo> ValidateAll(IValidateableModel model);

        /// <summary>
        /// Adds rule to validator
        /// </summary>
        /// <param name="propName">Property name</param>
        /// <param name="rule">Validation rule instance</param>
        /// <param name="constantRule">Is yes, rule will be applied on any property changed. If no - only for changed property.</param>
        void AddRule(string propName, IValidationRule rule, bool constantRule = false);

        /// <summary>
        /// Adds conditional rule to validator. Validation info for master property will be set to slave property.
        /// </summary>
        /// <param name="masterPropName">Master property (Property to validate).</param>
        /// <param name="slavePropName">Slave property (Property to set validation info).</param>
        /// <param name="rule">Validation rule.</param>
        void AddConditionalRule(string masterPropName, string slavePropName, IValidationRule rule);
    }
}
